<template>
  <view class="buy-section">
    <view
      class="action-info"
      v-if="item.use_attr == 0 && item.food_ext_goods_id == 0"
    >
      <template v-if="num">
        <view class="add-buy" @click.stop="handleBuy('reduce')">
          <i class="iconfont icon-sami-select"></i>
        </view>

        <view class="num">{{ num }}</view>
      </template>

      <view class="add-buy" @click.stop="handleBuy('add')">
        <i class="iconfont icon-add-select"></i>
      </view>
    </view>
    <view v-else class="add-buy add-buy2" @click.stop="handleBuy('add')">
      选规格
      <view class="num" v-if="num">{{ num }}</view>
    </view>
  </view>
</template>

<script>
export default {
  props: {
    propsData: {
      type: Object,
      default: () => {
        return {};
      },
    },
    num: {
      type: Number,
      default: 0,
    },
    item: {
      type: Object,
      default() {
        return null;
      },
    },
  },

  computed: {
    buyStyle() {
      return this.propsData.params.buyStyle;
    },
    buyBtnText() {
      return this.propsData.params.buyBtnText;
    },
  },

  methods: {
    handleBuy(type) {
      this.$emit("handleBuy", type);
    },
  },
};
</script>

<style scoped lang="scss">
.buy-section {
  width: 100%;

  .cart-buy {
    .iconfont {
      font-size: 50rpx;
      color: #333333;
    }
  }
  .add-buy {
    width: 48rpx;
    height: 48rpx;
    background: #fa2c1b;
    border-radius: 16rpx;
    display: flex;
    justify-content: center;
    align-items: center;
    .iconfont {
      font-size: 40rpx;
      color: #ffffff;
    }
  }

  .add-buy2 {
    position: relative;
    width: auto;
    padding: 0 10rpx;
    color: #fff;

    .num {
      width: 32rpx;
      height: 32rpx;
      background: #f84a33;
      border-radius: 50%;
      display: flex;
      justify-content: center;
      align-items: center;
      font-size: 20rpx;
      font-family: PingFang SC;
      font-weight: 600;
      color: #ffffff;
      position: absolute;
      right: -16rpx;
      top: -16rpx;
    }
  }

  .word-buy {
    height: 6.4vw;
    padding: 0 2.67vw;
    font-size: 24rpx;
    font-family: PingFang SC;
    font-weight: 400;
    color: #ffffff;
    display: flex;
    justify-items: center;
    align-items: center;
    background: #fa2c1b;
    border-radius: 3.2vw;
  }
}

.action-info {
  display: flex;
  align-items: center;
  .num {
    width: 50rpx;
    text-align: center;
  }
}
</style>
